package cn.tj.controller;

import cn.tj.entity.PageBean;
import cn.tj.entity.Register;
import cn.tj.entity.Result;
import cn.tj.entity.User;
import cn.tj.service.RegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Date;

@RestController
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    private RegisterService registerService;

    /**
     * 条件分页查询
     * @param currentPage
     * @param pageSize
     * @param account
     * @param minTime
     * @param maxTime
     * @return
     */
    @GetMapping("listByPage")
    public Result<PageBean<Register>> listByPage(
            Integer currentPage,
            Integer pageSize,
            @RequestParam(required = false) String account,//账号名
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date minTime,//最小时间
            @RequestParam(required = false) @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date maxTime//最大时间
            ){
         PageBean pb= registerService.listByPage(currentPage,pageSize,account,minTime,maxTime);
         return Result.success(pb);
    }

    /**
     * 通过审核，提交到用户表
     * @param user
     * @return
     */
    @PostMapping("/check")
    public Result check(@RequestBody User user){
        registerService.check(user);
        return Result.success();
    }

    /**
     * 通过id删除信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete")
    public Result delete(Integer id){
        registerService.delete(id);
        return Result.success();
    }
}
